//
//  ZYLiveSpecialextra.m
//
//  Created by Yeewii@hotmail com on 16/6/29
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ZYLiveSpecialextra.h"
#import "ZYLiveLiveInfo.h"


NSString *const kZYLiveSpecialextraUrl3w = @"url_3w";
NSString *const kZYLiveSpecialextraDigest = @"digest";
NSString *const kZYLiveSpecialextraLtitle = @"ltitle";
NSString *const kZYLiveSpecialextraSubtitle = @"subtitle";
NSString *const kZYLiveSpecialextraImgsrc = @"imgsrc";
NSString *const kZYLiveSpecialextraLmodify = @"lmodify";
NSString *const kZYLiveSpecialextraPriority = @"priority";
NSString *const kZYLiveSpecialextraSource = @"source";
NSString *const kZYLiveSpecialextraSkipID = @"skipID";
NSString *const kZYLiveSpecialextraTitle = @"title";
NSString *const kZYLiveSpecialextraPtime = @"ptime";
NSString *const kZYLiveSpecialextraTAG = @"TAG";
NSString *const kZYLiveSpecialextraDocid = @"docid";
NSString *const kZYLiveSpecialextraLiveInfo = @"live_info";
NSString *const kZYLiveSpecialextraUrl = @"url";
NSString *const kZYLiveSpecialextraPostid = @"postid";
NSString *const kZYLiveSpecialextraBoardid = @"boardid";
NSString *const kZYLiveSpecialextraTAGS = @"TAGS";
NSString *const kZYLiveSpecialextraSkipType = @"skipType";


@interface ZYLiveSpecialextra ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZYLiveSpecialextra

@synthesize url3w = _url3w;
@synthesize digest = _digest;
@synthesize ltitle = _ltitle;
@synthesize subtitle = _subtitle;
@synthesize imgsrc = _imgsrc;
@synthesize lmodify = _lmodify;
@synthesize priority = _priority;
@synthesize source = _source;
@synthesize skipID = _skipID;
@synthesize title = _title;
@synthesize ptime = _ptime;
@synthesize tAG = _tAG;
@synthesize docid = _docid;
@synthesize liveInfo = _liveInfo;
@synthesize url = _url;
@synthesize postid = _postid;
@synthesize boardid = _boardid;
@synthesize tAGS = _tAGS;
@synthesize skipType = _skipType;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.url3w = [self objectOrNilForKey:kZYLiveSpecialextraUrl3w fromDictionary:dict];
            self.digest = [self objectOrNilForKey:kZYLiveSpecialextraDigest fromDictionary:dict];
            self.ltitle = [self objectOrNilForKey:kZYLiveSpecialextraLtitle fromDictionary:dict];
            self.subtitle = [self objectOrNilForKey:kZYLiveSpecialextraSubtitle fromDictionary:dict];
            self.imgsrc = [self objectOrNilForKey:kZYLiveSpecialextraImgsrc fromDictionary:dict];
            self.lmodify = [self objectOrNilForKey:kZYLiveSpecialextraLmodify fromDictionary:dict];
            self.priority = [[self objectOrNilForKey:kZYLiveSpecialextraPriority fromDictionary:dict] doubleValue];
            self.source = [self objectOrNilForKey:kZYLiveSpecialextraSource fromDictionary:dict];
            self.skipID = [self objectOrNilForKey:kZYLiveSpecialextraSkipID fromDictionary:dict];
            self.title = [self objectOrNilForKey:kZYLiveSpecialextraTitle fromDictionary:dict];
            self.ptime = [self objectOrNilForKey:kZYLiveSpecialextraPtime fromDictionary:dict];
            self.tAG = [self objectOrNilForKey:kZYLiveSpecialextraTAG fromDictionary:dict];
            self.docid = [self objectOrNilForKey:kZYLiveSpecialextraDocid fromDictionary:dict];
            self.liveInfo = [ZYLiveLiveInfo modelObjectWithDictionary:[dict objectForKey:kZYLiveSpecialextraLiveInfo]];
            self.url = [self objectOrNilForKey:kZYLiveSpecialextraUrl fromDictionary:dict];
            self.postid = [self objectOrNilForKey:kZYLiveSpecialextraPostid fromDictionary:dict];
            self.boardid = [self objectOrNilForKey:kZYLiveSpecialextraBoardid fromDictionary:dict];
            self.tAGS = [self objectOrNilForKey:kZYLiveSpecialextraTAGS fromDictionary:dict];
            self.skipType = [self objectOrNilForKey:kZYLiveSpecialextraSkipType fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.url3w forKey:kZYLiveSpecialextraUrl3w];
    [mutableDict setValue:self.digest forKey:kZYLiveSpecialextraDigest];
    [mutableDict setValue:self.ltitle forKey:kZYLiveSpecialextraLtitle];
    [mutableDict setValue:self.subtitle forKey:kZYLiveSpecialextraSubtitle];
    [mutableDict setValue:self.imgsrc forKey:kZYLiveSpecialextraImgsrc];
    [mutableDict setValue:self.lmodify forKey:kZYLiveSpecialextraLmodify];
    [mutableDict setValue:[NSNumber numberWithDouble:self.priority] forKey:kZYLiveSpecialextraPriority];
    [mutableDict setValue:self.source forKey:kZYLiveSpecialextraSource];
    [mutableDict setValue:self.skipID forKey:kZYLiveSpecialextraSkipID];
    [mutableDict setValue:self.title forKey:kZYLiveSpecialextraTitle];
    [mutableDict setValue:self.ptime forKey:kZYLiveSpecialextraPtime];
    [mutableDict setValue:self.tAG forKey:kZYLiveSpecialextraTAG];
    [mutableDict setValue:self.docid forKey:kZYLiveSpecialextraDocid];
    [mutableDict setValue:[self.liveInfo dictionaryRepresentation] forKey:kZYLiveSpecialextraLiveInfo];
    [mutableDict setValue:self.url forKey:kZYLiveSpecialextraUrl];
    [mutableDict setValue:self.postid forKey:kZYLiveSpecialextraPostid];
    [mutableDict setValue:self.boardid forKey:kZYLiveSpecialextraBoardid];
    [mutableDict setValue:self.tAGS forKey:kZYLiveSpecialextraTAGS];
    [mutableDict setValue:self.skipType forKey:kZYLiveSpecialextraSkipType];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.url3w = [aDecoder decodeObjectForKey:kZYLiveSpecialextraUrl3w];
    self.digest = [aDecoder decodeObjectForKey:kZYLiveSpecialextraDigest];
    self.ltitle = [aDecoder decodeObjectForKey:kZYLiveSpecialextraLtitle];
    self.subtitle = [aDecoder decodeObjectForKey:kZYLiveSpecialextraSubtitle];
    self.imgsrc = [aDecoder decodeObjectForKey:kZYLiveSpecialextraImgsrc];
    self.lmodify = [aDecoder decodeObjectForKey:kZYLiveSpecialextraLmodify];
    self.priority = [aDecoder decodeDoubleForKey:kZYLiveSpecialextraPriority];
    self.source = [aDecoder decodeObjectForKey:kZYLiveSpecialextraSource];
    self.skipID = [aDecoder decodeObjectForKey:kZYLiveSpecialextraSkipID];
    self.title = [aDecoder decodeObjectForKey:kZYLiveSpecialextraTitle];
    self.ptime = [aDecoder decodeObjectForKey:kZYLiveSpecialextraPtime];
    self.tAG = [aDecoder decodeObjectForKey:kZYLiveSpecialextraTAG];
    self.docid = [aDecoder decodeObjectForKey:kZYLiveSpecialextraDocid];
    self.liveInfo = [aDecoder decodeObjectForKey:kZYLiveSpecialextraLiveInfo];
    self.url = [aDecoder decodeObjectForKey:kZYLiveSpecialextraUrl];
    self.postid = [aDecoder decodeObjectForKey:kZYLiveSpecialextraPostid];
    self.boardid = [aDecoder decodeObjectForKey:kZYLiveSpecialextraBoardid];
    self.tAGS = [aDecoder decodeObjectForKey:kZYLiveSpecialextraTAGS];
    self.skipType = [aDecoder decodeObjectForKey:kZYLiveSpecialextraSkipType];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_url3w forKey:kZYLiveSpecialextraUrl3w];
    [aCoder encodeObject:_digest forKey:kZYLiveSpecialextraDigest];
    [aCoder encodeObject:_ltitle forKey:kZYLiveSpecialextraLtitle];
    [aCoder encodeObject:_subtitle forKey:kZYLiveSpecialextraSubtitle];
    [aCoder encodeObject:_imgsrc forKey:kZYLiveSpecialextraImgsrc];
    [aCoder encodeObject:_lmodify forKey:kZYLiveSpecialextraLmodify];
    [aCoder encodeDouble:_priority forKey:kZYLiveSpecialextraPriority];
    [aCoder encodeObject:_source forKey:kZYLiveSpecialextraSource];
    [aCoder encodeObject:_skipID forKey:kZYLiveSpecialextraSkipID];
    [aCoder encodeObject:_title forKey:kZYLiveSpecialextraTitle];
    [aCoder encodeObject:_ptime forKey:kZYLiveSpecialextraPtime];
    [aCoder encodeObject:_tAG forKey:kZYLiveSpecialextraTAG];
    [aCoder encodeObject:_docid forKey:kZYLiveSpecialextraDocid];
    [aCoder encodeObject:_liveInfo forKey:kZYLiveSpecialextraLiveInfo];
    [aCoder encodeObject:_url forKey:kZYLiveSpecialextraUrl];
    [aCoder encodeObject:_postid forKey:kZYLiveSpecialextraPostid];
    [aCoder encodeObject:_boardid forKey:kZYLiveSpecialextraBoardid];
    [aCoder encodeObject:_tAGS forKey:kZYLiveSpecialextraTAGS];
    [aCoder encodeObject:_skipType forKey:kZYLiveSpecialextraSkipType];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZYLiveSpecialextra *copy = [[ZYLiveSpecialextra alloc] init];
    
    if (copy) {

        copy.url3w = [self.url3w copyWithZone:zone];
        copy.digest = [self.digest copyWithZone:zone];
        copy.ltitle = [self.ltitle copyWithZone:zone];
        copy.subtitle = [self.subtitle copyWithZone:zone];
        copy.imgsrc = [self.imgsrc copyWithZone:zone];
        copy.lmodify = [self.lmodify copyWithZone:zone];
        copy.priority = self.priority;
        copy.source = [self.source copyWithZone:zone];
        copy.skipID = [self.skipID copyWithZone:zone];
        copy.title = [self.title copyWithZone:zone];
        copy.ptime = [self.ptime copyWithZone:zone];
        copy.tAG = [self.tAG copyWithZone:zone];
        copy.docid = [self.docid copyWithZone:zone];
        copy.liveInfo = [self.liveInfo copyWithZone:zone];
        copy.url = [self.url copyWithZone:zone];
        copy.postid = [self.postid copyWithZone:zone];
        copy.boardid = [self.boardid copyWithZone:zone];
        copy.tAGS = [self.tAGS copyWithZone:zone];
        copy.skipType = [self.skipType copyWithZone:zone];
    }
    
    return copy;
}


@end
